﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PBOffice.Models;
using PBOffice.BLL;

public partial class ScheduleManager_AddSchedule : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.btnDelete.Enabled = false;
       // this.lbName.Text = Session["username"].ToString();
        if (Request.QueryString["id"] != null)
        {
            this.btnDelete.Enabled = true;
            int noteId = Convert.ToInt32(Request.QueryString["id"]);
            MyNote note = new MyNoteManager().GetNoteById(noteId);
            this.txtTitle.Text = note.NoteTitle;
            this.txtContent.Text = note.NoteContent;
            this.lbName.Text = note.CreateUser;
            this.lbTime.Text = note.CreateTime.ToString();
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (this.txtTitle.Text != "")
        {
            MyNote note = new MyNote();
            note.NoteTitle = this.txtTitle.Text.Trim();
            note.NoteContent = this.txtContent.Text.Trim();
            note.CreateUser = this.lbName.Text.Trim();

            if (Request.QueryString["id"] != null)
            {
                note.NoteId = Convert.ToInt32(Request.QueryString["id"]);
                note.CreateTime = Convert.ToDateTime(this.lbTime.Text);
                new MyNoteManager().UpdateNote(note);
            }
            else
            {
                note.CreateTime = DateTime.Now;
                new MyNoteManager().AddNote(note);
            }
        }
        this.txtTitle.Text = "";
        this.txtContent.Text = "";
        this.btnDelete.Enabled = false;
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        int noteId = Convert.ToInt32(Request.QueryString["id"]);
        new MyNoteManager().DeleteNote(noteId);
        this.txtTitle.Text = "";
        this.txtContent.Text = "";
        this.btnDelete.Enabled = false;
    }
}